package com.magic.gre.mvp.presenter;

import com.google.gson.reflect.TypeToken;
import com.magic.gre.entity.WordsBean;
import com.magic.gre.entity.base.BaseListModel;
import com.magic.gre.mvp.contract.SearchContract;
import com.magic.gre.mvp.model.SearchModelImpl;
import com.noname.lib_base_java.mvp.BasePresenterImpl;

/**
 * Author: Lmoumou
 * Date: 2019-01-14 16:33
 * 文件名: SearchPresenterImpl
 * 描述:
 */
public class SearchPresenterImpl extends BasePresenterImpl<SearchContract.View, SearchContract.Model>
        implements SearchContract.Presenter {
    public SearchPresenterImpl(SearchContract.View view) {
        super(view);
    }

    @Override
    protected SearchContract.Model creatModel() {
        return new SearchModelImpl();
    }

    @Override
    public void pSearch(String search) {
        mModel.mSearch(new CommonObserver<BaseListModel<WordsBean>>(new TypeToken<BaseListModel<WordsBean>>(){}.getType()) {
            @Override
            protected void onSuccess(BaseListModel<WordsBean> wordsBeanBaseListModel) {
                mView.vSearch(wordsBeanBaseListModel.body);
            }

            @Override
            public void onError(int status, String msg) {

            }
        }, search);
    }
}
